package com.leyou.trade.web;

import com.leyou.trade.dto.PayResultDTO;
import com.leyou.trade.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.Map;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/url/{id}")
    public ResponseEntity<String> getPayUrl(@PathVariable("id")Long orderId){

        return ResponseEntity.ok(this.orderService.getPayUrl(orderId));
    }

    @PostMapping(value = "/wx/notify",produces =  MediaType.APPLICATION_XML_VALUE)//,consumes = "application/xml"
    public ResponseEntity<PayResultDTO> handleNotify(@RequestBody Map<String,String> data){

        this.orderService.handleNotify(data);

        return ResponseEntity.ok(new PayResultDTO());
    }

    /**
     * @Author: hyy
     * @Description:查询订单支付的状态
     * @Date: 18:47 2020/8/5
     * @param: null
     * @return:
     * @Version: 1.0
     */

    @GetMapping("/state/{id}")
    public  ResponseEntity<Integer> queryOrderStatus(@PathVariable("id") Long orderId){

        return  ResponseEntity.ok(orderService.queryPayStatus(orderId));
    }
}
